package org.sdfc.model.attr.key

import com.documentum.fc.common.IDfAttr

/** Operations on KeyAttributes.
 */
object KeyAttributeOps {
  
  /** Converts an IDfAttr into the corresponding KeyAttribute.
   */
  def convert(attr : IDfAttr) : KeyAttribute[Any] = {
    val name = attr.getName
    val dataType = attr.getDataType
    
    if ( attr.isRepeating() )
      dataType match {
        case IDfAttr.DM_BOOLEAN => new KRepeatingBooleanAttribute(name)
        case IDfAttr.DM_INTEGER => new KRepeatingIntAttribute(name)
        case IDfAttr.DM_STRING  => new KRepeatingStringAttribute(name)
        case IDfAttr.DM_ID      => new KRepeatingIdAttribute(name)
        case IDfAttr.DM_TIME    => new KRepeatingTimeAttribute(name)
        case IDfAttr.DM_DOUBLE  => new KRepeatingDoubleAttribute(name)
      }
    else
      dataType match {
        case IDfAttr.DM_BOOLEAN => new KSingleBooleanAttribute(name)
        case IDfAttr.DM_INTEGER => new KSingleIntAttribute(name)
        case IDfAttr.DM_STRING  => new KSingleStringAttribute(name)
        case IDfAttr.DM_ID      => new KSingleIdAttribute(name)
        case IDfAttr.DM_TIME    => new KSingleTimeAttribute(name)
        case IDfAttr.DM_DOUBLE  => new KSingleDoubleAttribute(name)
      }
  }
  
}
